<?php

session_start();
if (isset($_SESSION['login'])) {
    // header('Location:localhost/thtp.ru/user/' . $_SESSION[''])
}
require_once CORE_PATH . DS . 'library' . DS . 'dbconf.php';

/**
 * class autoload
 */
function __autoload($class) {
    $file = str_replace('_', DS, $class);
    $file = strtolower($file . '.php');
    require_once $file;
}
function tosmall($class) {
    $file = str_replace('_', DS, $class);
    $file = strtolower($file . '.php');
    return $file;
}
/**
 * get routes get actions  get controllers
 */
$router = Core_Library_Router::instance();
$router->getRoute();
$controller = $router->getController();
$action = $router->getAction();
$params = $router->getParams();
$class = APP_PATH . '_controllers_' . $controller;
$requireClass = tosmall($class);
echo $controller . ' --- ' . $action . ' ---- ' . $params . '  in bootstrap<br>';
echo $requireClass;
if (file_exists($requireClass)) {
    $class = new $class();
    if (!method_exists($class, $action)) {
        $params = $action;
        $action = 'index';
    }
    $class->$action($params);
}else{
    echo '2nd';
    $class = APP_PATH . '_controllers_articles';
    $action = 'index';
    $params = $controller;
    $class = new $class();
    $class->$action($params);
    $controller = 'articles';
    $action ='index';
    //echo "умри сука!"; die();
}

$view = new Core_Library_View_View($controller, $action);
$view->render();
?>
